/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * dlgEditMails.java
 *
 * Created on 1-ago-2011, 15.00.28
 */
package UI.clienti.dialogs;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author mrossetti
 */
public class dlgEditMails extends javax.swing.JDialog {

    private JTable TabMod;
    /** Creates new form dlgEditMails */
    public dlgEditMails(java.awt.Frame parent, JTable Tab, boolean modal) {
        super(parent, modal);
        initComponents();
        TabMod = Tab;
        txtIndirizzo.setText(TabMod.getValueAt(TabMod.getSelectedRow(), 0).toString());
        txtRif.setText(TabMod.getValueAt(TabMod.getSelectedRow(), 1).toString());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtIndirizzo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtRif = new javax.swing.JTextField();
        cmdOk = new javax.swing.JButton();
        cmdEsci = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Indirizzo e-mail");

        jLabel2.setText("Riferimento");

        cmdOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/common/ok.png.png"))); // NOI18N
        cmdOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdOkActionPerformed(evt);
            }
        });

        cmdEsci.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/common/cancel.png"))); // NOI18N
        cmdEsci.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdEsciActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtIndirizzo, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(txtRif, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cmdOk)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 262, Short.MAX_VALUE)
                        .addComponent(cmdEsci)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtIndirizzo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtRif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdOk)
                    .addComponent(cmdEsci))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmdEsciActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdEsciActionPerformed
        if(txtIndirizzo.getText().equals("") && txtRif.getText().equals("")){
            ((DefaultTableModel)TabMod.getModel()).removeRow(TabMod.getSelectedRow());
        }
        setVisible(false);
        dispose();
    }//GEN-LAST:event_cmdEsciActionPerformed

    private void cmdOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOkActionPerformed
        if(txtIndirizzo.getText().equals("") && txtRif.getText().equals("")){
            ((DefaultTableModel)TabMod.getModel()).removeRow(TabMod.getSelectedRow());
        }else{
            TabMod.setValueAt(txtIndirizzo.getText(), TabMod.getSelectedRow(), 0);
            TabMod.setValueAt(txtRif.getText(), TabMod.getSelectedRow(), 1);
        }
        setVisible(false);
        dispose();
    }//GEN-LAST:event_cmdOkActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdEsci;
    private javax.swing.JButton cmdOk;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField txtIndirizzo;
    private javax.swing.JTextField txtRif;
    // End of variables declaration//GEN-END:variables
}
